package com.example.administrator.managesystem.activity.my_profile;

import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.net.Uri;
import android.util.Log;
import android.widget.MediaController;
import android.widget.Toast;
import android.widget.VideoView;

import com.example.administrator.managesystem.R;
import com.example.administrator.managesystem.base.BaseActivity;
import com.example.administrator.managesystem.base.BaseAdapter;
import com.example.administrator.managesystem.utils.GlobalConfig;
import com.example.administrator.managesystem.utils.StatusBarUtil;
import com.example.administrator.managesystem.utils.ToastUtils;

public class VideoPreviewActivity extends BaseActivity {

    private VideoView videoView ;
    @Override
    public void initView() {
        //状态栏
        StatusBarUtil.setWindowStatusBarColor(this,R.color.black);
        showfloatButton(true,true);
        videoView =findViewById(R.id.videoView );


    }

    @Override
    public void doBusiness() {
        if(!getIntent().getStringExtra("video_url").isEmpty()){
            showProgressDialog();
        }else{
            return;
        }
       // Log.e("msg","GlobalConfig.LOCAL_HTTP+\"\"+getIntent().getStringExtra(\"video_url\"):"+GlobalConfig.LOCAL_HTTP+""+getIntent().getStringExtra("video_url"));
        Uri uri = Uri.parse(GlobalConfig.ONLINE_HTTP+""+getIntent().getStringExtra("video_url"));
        //设置视频控制器
        videoView.setMediaController(new MediaController(this));
        //播放完成回调
        videoView.setOnCompletionListener( new MyPlayerOnCompletionListener());
        videoView.setOnPreparedListener(new MyOnPreparedListener());


        //设置视频路径
        videoView.setVideoURI(uri);

        //开始播放视频
        videoView.start();
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_video_preview;
    }
    class MyPlayerOnCompletionListener implements MediaPlayer.OnCompletionListener {

        @Override
        public void onCompletion(MediaPlayer mp) {
          //  Toast.makeText( LocalVideoActivity.this, "播放完成了", Toast.LENGTH_SHORT).show();
        }
    }

    class MyOnPreparedListener implements  MediaPlayer.OnPreparedListener {


        @Override
        public void onPrepared(MediaPlayer mp) {
            dismissProgressDialog();
        }
    }



}
